#ifdef WX_PRECOMP
#include "wx_pch.h"
#else
#include <wx/wx.h>
#endif //WX_PRECOMP

#include "unit_part_parser.h"
#include "exchanger.h"

// Parce one item from XML document
bool UnitPartParser::OnParceComplete()
{
  Item.Type = ComponentCellType;
  Result.push_back(Item);
  Item.Clear();
  return true;
}

const CellDataItemListType& UnitPartParser::GetResult() const
{
  return Result;
}

UnitPartParser::UnitPartParser()
  : ComponentCellType(CELL_NONE)
{
  SetHandler(wxT("id"), &Item.ComponentID, Exchanger::ForInteger());
  SetHandler(wxT("race_id"), &Item.RaceID, Exchanger::ForInteger());
  SetHandler(wxT("lvl"), &Item.ComponentLevel, Exchanger::ForInteger());
}

void UnitPartParser::Clear()
{
  Item.Clear();
  Result.clear();
}

void UnitPartParser::SetCellType(const CellsType& cellType)
{
  ComponentCellType = cellType;
}

void UnitPartParser::SetItem(const CellDataItem& item)
{
  Item = item;
}
